package com.jlpay.openapi.demo.clearing.notify;


import com.jlpay.open.jlpay.sdk.java.enums.SignType;
import com.jlpay.open.jlpay.sdk.java.exception.SignVerifyException;
import com.jlpay.open.jlpay.sdk.java.model.notify.NotifyParam;
import com.jlpay.openapi.demo.JlpayOpenApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/***
 * 消息回调
 * @author xuexiaoya
 * @date 2024/3/14
 **/

public class MsgNotifyService {

    private static final Logger LOGGER = LoggerFactory.getLogger(MsgNotifyService.class);


    public static void main(String[] args) {
        // 使用 @RequestHeader Map<String, String> headers,@RequestBody String msg 传入请求
        String msg = "{\"merch_no\":\"84944035812S123\",\"settle_type\":\"T0\",\"amount\":\"2000\",\"fee_amount\":\"300\",\"out_settle_id\":\"191912345678901894\",\"settle_id\":\"411109630795649800601630\",\"postscript\":\"postscript\",\"payment_time\":\"2024-02-21 14:50:22\",\"org_no\":\"123456\",\"result_state\":\"SUCCESS\"}";
        NotifyParam notifyParam = NotifyParam.builder()
                .method("POST")
                .uri("/crypto/verify")
                .alg(SignType.SM3_WITH_SM2_WITH_DER.getCode())
                .sign("MEQCIEU+OklDOcMcMbNz7ZQygZbvuyxcArDIXYcARay4InNBAiA0X3PGQ9ajaRfoLGfL2uAyYZ2zy+cpUyo/aFdFGeaKIA==")
                .nonce("DtIaE53ryRULHmmez7jbiyXE2YN7jgJJ")
                .timestamp("1710467996")
                .body(msg)
                .build();
        NotifyDto dto = null;
        try {
            dto = JlpayOpenApiService.notifyParseService().parse(notifyParam, NotifyDto.class);
        } catch (SignVerifyException e) {
            // 签名验证失败
            LOGGER.error("签名验证失败", e);
        }
    }
}
